<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>九宫格布局</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        #container {
            box-sizing: border-box;
            margin: 0 auto;
            width: 540px;
            height: 540px;
            /* background: green; */
            display: flex;
            flex-wrap: wrap;
        }
        
        #container .div1 {
            text-align: center;
            line-height: 170px;
            box-sizing: border-box;
            margin-right: 0.16rem;
            flex: 0 0 33%;
            height: 33%;
            border: 1px solid red;
        }
        
        #container .div1:nth-child(5),
        #container .div1:nth-child(11),
        #container .div1:nth-child(17) {
            /* background: red; */
            margin-right: 0;
        }
    </style>
</head>

<body>
    <div id="container">
        <div class="div1">1</div><br />
        <div class="div1">2</div><br />
        <div class="div1">3</div><br />
        <div class="div1">4</div><br />
        <div class="div1">5</div><br />
        <div class="div1">6</div><br />
        <div class="div1">7</div><br />
        <div class="div1">8</div><br />
        <div class="div1">9</div>

</body>

</html>